#define _CRT_SECURE_NO_WARNINGS 1

#include"SList.h"

void TestSList1()//测试尾插头插
{
	SLNode* pList = NULL;
	SListPushBack(&pList, 1);
	SListPushBack(&pList, 2);
	SListPushBack(&pList, 3);
	SListPushBack(&pList, 4);

	SListPrint(pList);

	SListPushFront(&pList, 1);
	SListPushFront(&pList, 2);
	SListPushFront(&pList, 3);
	SListPushFront(&pList, 4);

	SListPrint(pList);
}

void TestSList2()//测试尾删头删
{
	SLNode* pList = NULL;
	SListPushBack(&pList, 1);
	SListPushBack(&pList, 2);
	SListPushBack(&pList, 3);
	SListPushBack(&pList, 4);
	SListPrint(pList);

	SListPopBack(&pList);
	SListPrint(pList);

	SListPopFront(&pList);
	SListPrint(pList);

	SListPopBack(&pList);
	SListPopBack(&pList);
	SListPrint(pList);
}

void TestSList3()//测试查找函数
{
	SLNode* pList = NULL;
	SListPushFront(&pList, 1);
	SListPushFront(&pList, 2);
	SListPushFront(&pList, 3);
	SListPushFront(&pList, 2);
	SListPushFront(&pList, 4);
	SListPushFront(&pList, 2);
	SListPushFront(&pList, 2);
	SListPushFront(&pList, 4);
	SListPrint(pList);

	SLNode* pos = SListFind(pList, 2);
	for (int i = 0;pos != NULL;i++)
	{
		printf("第%d个pos节点:%p->%d\n", i, pos, pos->data);
		pos->data = 9;//查找过程中把2改成9  返回SLNode*的好处
		pos = SListFind(pos->next, 2);
	}
	SListPrint(pList);
}

void TestSList4()//测试指定位置的前面插入
{
	SLNode* pList = NULL;
	SListPushBack(&pList, 1);
	SListPushBack(&pList, 2);
	SListPushBack(&pList, 3);
	SListPushBack(&pList, 4);

	SListPrint(pList);

	SLNode* pos = SListFind(pList, 2);
	SListInsert(&pList, pos, 60);

	SListPrint(pList);

	pos = SListFind(pList, 1);
	SListInsert(&pList, pos, 70);
	SListPrint(pList);

	SListInsert(&pList, NULL, 80);
	SListPrint(pList);
}

void TestSList5()//测试指定位置的后面插入
{
	SLNode* pList = NULL;
	SListPushBack(&pList, 1);
	SListPushBack(&pList, 2);
	SListPushBack(&pList, 3);
	SListPushBack(&pList, 4);
	SListPrint(pList);

	SLNode* pos = SListFind(pList, 3);
	SListInsertAfter(pos, 10);
	SListPrint(pList);

	pos = SListFind(pList, 4);
	SListInsertAfter(pos, 20);
	SListPrint(pList);

	pos = SListFind(pList, 1);
	SListInsertAfter(pos, 30);
	SListPrint(pList);
}

void TestSList6()//测试指定位置的删除
{
	SLNode* pList = NULL;
	SListPushBack(&pList, 1);
	SListPushBack(&pList, 2);
	SListPushBack(&pList, 3);
	SListPushBack(&pList, 4);
	SListPrint(pList);

	SLNode* pos = SListFind(pList, 3);
	SListEarse(&pList, pos);
	SListPrint(pList);

	pos = SListFind(pList, 1);
	SListEarse(&pList, pos);
	SListPrint(pList);

	pos = SListFind(pList, 2);
	SListEarse(&pList, pos);
	SListPrint(pList);

	pos = SListFind(pList, 4);
	SListEarse(&pList, pos);
	SListPrint(pList);
}

void TestSList7()//测试指定位置之后的删除和整个链表销毁
{
	SLNode* pList = NULL;
	SListPushBack(&pList, 1);
	SListPushBack(&pList, 2);
	SListPushBack(&pList, 3);
	SListPushBack(&pList, 4);
	SListPrint(pList);
	//SListDestroy(&pList);
	//SListPrint(pList);

	SLNode* pos = SListFind(pList, 3);
	SListEarseAfter(pos);
	SListPrint(pList);

	pos = SListFind(pList, 1);
	SListEarseAfter(pos);
	SListPrint(pList);

	pos = SListFind(pList, 1);
	SListEarseAfter(pos);
	SListPrint(pList);

	SListDestroy(&pList);
	SListPrint(pList);
}

void TestSList8()
{
	SLNode* pLista = NULL;
	SListPushBack(&pLista, 1);
	SListPushBack(&pLista, 3);
	SListPushBack(&pLista, 5);
	SListPushBack(&pLista, 8);
	SListPrint(pLista);

	SLNode* pListb = NULL;
	SListPushBack(&pListb, 1);
	SListPushBack(&pListb, 6);
	SListPushBack(&pListb, 8);
	SListPushBack(&pListb, 9);
	SListPrint(pListb);

	SLNode* pListc = SListMerge(pLista, pListb);
	SListPrint(pListc);

	pLista = NULL;
	pListb = NULL;
	SListDestroy(&pListc);
}

int main()
{
	//TestSList1();//测试尾插头插
	//TestSList2();//测试尾删头删
	//TestSList3();//测试查找函数
	//TestSList4();//测试指定位置的前面插入
	//TestSList5();//测试指定位置的后面插入
	//TestSList6();//测试指定位置的删除
	//TestSList7();//测试指定位置之后的删除和整个链表销毁
	TestSList8();//测试合并两个顺序表
	return 0;
}